#	$Id: mod.mk 1083 2010-05-02 19:03:21Z phrakt $
#

.if exists(${.CURDIR}/../Makefile.inc) && !defined(MK_DOT_INC)
.include "${.CURDIR}/../Makefile.inc"
MK_DOT_INC=1
.endif

.if !defined(MOD_NAME)
.error "MOD_NAME is not defined"
.endif


SRCS?=		${MOD_NAME}.c
OBJS?=		${SRCS:N*.h:R:S/$/.o/g}
MODEXT?=	.so
MODFILE?=	${MOD_NAME}${MODEXT}


MOD_AUTHOR?=	Anonymous
MOD_DESC?=	No description
MOD_VERSION?=	0.1


MOD_VMAJOR=	${MOD_VERSION:C/\..*//}
MOD_VMINOR=	${MOD_VERSION:C/[^.]\.//}


CPPFLAGS+=	-DMOD_NAME="\"${MOD_NAME}\""
CPPFLAGS+=	-DMOD_AUTHOR="\"${MOD_AUTHOR}\""
CPPFLAGS+=	-DMOD_DESC="\"${MOD_DESC}\""
CPPFLAGS+=	-DMOD_VERSION_MAJOR=${MOD_VMAJOR}
CPPFLAGS+=	-DMOD_VERSION_MINOR=${MOD_VMINOR}



CFLAGS+=	${PICFLAGS}
LDFLAGS+=	-shared




.MAIN: all

all: ${MODFILE} _SUBDIRUSE



${MODFILE}: ${OBJS}
	${LD} ${LDFLAGS} -o ${MODFILE} ${OBJS} ${LDADD}

${MODNAME}: ${MODFILE}

module: ${MODFILE}


.if !target(clean)
clean: _SUBDIRUSE
	rm -rf ${MODFILE} ${OBJS} ${CLEANFILES}
.endif


cleandir: _SUBDIRUSE clean
	rm -f .depend


.if !target(beforeinstall)
beforeinstall:
	@if [ ! -e ${DESTDIR}${MODDIR} ]; then				\
		${MKDIR} ${DESTDIR}${MODDIR};				\
	fi
.endif

.if !target(install)
install: ${MODFILE} beforeinstall
	${INSTALL} -o ${MODOWN} -g ${MODGRP} -m ${MODMODE} \
	    ${MODFILE} ${DESTDIR}${MODDIR}/${MODFILE}
.endif

.if !target(afterinstall)
afterinstall: install
.endif

.if !defined(NOMAN)
.include "man.mk"
.endif

.include "dep.mk"
.include "subdir.mk"
